<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>推荐商品页面</title>
	<style>
		#page_end{
			float:left;
			width:300px;
			height:50px;
			/* margin: 0 auto; */
			margin-left:400px;
		}
		.page_style{
			width:50px;
			height:30px;
			background-color:#3477c8;
			float:left;
			margin-left:10px;
			margin-top:10px;
			margin-bottom:10px;
			text-align:center;
			line-height:30px;
		}
		.page_style a{
			color:white;
			font-size:14px;
		}
	</style>
</head>
<body>
<?php 
	include_once("common/init.php");
	$whereSql = "  isno=0 and isnice=1 and status='已审核'";
	$cat_title = "推荐商品";
	include_once("header.php");
// 定义分页原理
    $page = isset($_GET["page"]) ? $_GET["page"] : 1; // 分页页码
    $arr["page"]=$page;
    $n = 8; // 每页要显示多少条
    $m = ($page - 1) * $n;
    $arr['m']=$m;
// 求总记录数
    $sql = "select * from goods where $whereSql  order by addtime desc";
    $result = mysql_query($sql);
    $total = mysql_num_rows($result);
    $maxpage = ceil($total / $n);
    $arr["maxpage"]=$maxpage;
    $limit = " limit $m,$n"; // 拼接的子句要加上空格
    $sql = "select * from goods where $whereSql  order by addtime desc" . $limit;
    $result = mysql_query($sql);
    if ($result){
        $nums = mysql_num_rows($result);
        if ($nums >= 1){
            while ($row = mysql_fetch_assoc($result)) {
                $infos[] = $row; // 将数据库表内容存储到二维数组infos中
            }
        }else{
            $infos = array(); //此时infos变量是false的；
        }
        $arr["infos"]=$infos;
    }else {
        echo "错误：" . mysql_error($link);
    }
	
?>
<div class="m_ctr">
    <div class="ej_tctr">当前位置：<a href="index.php">首页</a> > <?php echo $cat_title;?></div>
    <div class="m_ctr1">
        <?php 
		if($infos){
			$i=1;
		foreach($infos as $key => $value) {?>
		<div class="m_pctr1" onMouseOver="document.getElementById('x<?php echo $i;?>').className='m_pic11'" onMouseOut="document.getElementById('x<?php echo $i;?>').className='m_pic1'"  <?php if(is_int($i/4)){?> style="margin-right:0;"<?php }?>>
            <div class="m_pic1" id="x<?php echo $i;?>"><a href="goodsshow.php?id=<?php echo $value['id'];?>&categoryid=<?php echo $value['categoryid'];?>"><img src="./Public/Upload/<?php echo $value["img"];?>"></a></div>
            <div class="m_pt11"><a href="goodsshow.php?id=<?php echo $value['id'];?>&categoryid=<?php echo $value['categoryid'];?>"><?php echo $value['title'];?></a></div>
            <div class="m_pt12">
				￥<?php echo $value['sprice'];?>
				&emsp;<span>￥<?php echo $value['mprice'];?></span>
			</div>
        </div>
        <?php
		$i = $i+1; 
		}
		}
		?>
    </div>
	<div id="page_end">
	    <div class="page_style"><a href="goodst.php?page=1">首页</a></div>
	    <div class="page_style"><a href="goodst.php?page=<?= ($page==1)?1:$page-1;?>">上一页</a></div>
	    <div class="page_style"><a href="goodst.php?page=<?= $page==$maxpage?$maxpage:$page+1;?>">下一页</a></div>
	    <div class="page_style"><a href="goodst.php?page=<?= $maxpage;?>">尾页</a></div>
	</div>
</div>
<?php include_once("footer.php");?>
</body>
</html>